<?php

namespace app\common\model\xiluhouse;

use think\Model;
use traits\model\SoftDelete;

class Feedback extends Model
{

    use SoftDelete;

    // 表名
    protected $name = 'xiluhouse_feedback';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'audit_state_text',
    ];

    public function getAuditStateList()
    {
        return ['1' => __('Audit_state 1'), '2' => __('Audit_state 2')];
    }

    public function getAuditStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['audit_state']) ? $data['audit_state'] : '');
        $list = $this->getAuditStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function house()
    {
        return $this->belongsTo('app\common\model\xiluhouse\Rental', 'house_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function feedbacktype()
    {
        return $this->belongsTo('app\common\model\xiluhouse\FeedbackType', 'type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
